<template>
	<view class="ewm-page">
		<u-navbar title="加油码" :background="background" :border-bottom="false" title-color="#fff" back-icon-color="#fff">
			<view class="slot-wrap">
				<view class="">
					<text></text>
				</view>
				<!-- <view class="" @click="tabcl">
					<text>切换订单</text>
				</view> -->
			</view>
		</u-navbar>
		<view v-if="queryCodeList!=''" class="ewm-main">
			<view class="jym-fkm">
				<view class="" style="color:#FF0000; padding: 20rpx 0;">
					<text>优先使用加油金账户付款</text>
				</view>
				<view class="code-img">
					<image :src="binary" mode="" />
				</view>
				<view class="ykzhList">
					<u-dropdown title-size="36" ref="uDropdown" @open="open" @close="close">
						<u-dropdown-item v-model="fkID" @change="change" :border-bottom="true" :title="title"
							:options="options2">
						</u-dropdown-item>
					</u-dropdown>

				</view>
			</view>

			<!-- <u-popup v-model="showCJ" mode="bottom" width="90%" :closeable="true" border-radius="10">
				
			</u-popup> -->
			<!-- <view class="ERcode-orderinfo">
				<view class="ERcode-orderinfo-view"><text>{{queryCodeList.ORMTB440CA01||''}}</text><text
						style="color: red;">{{queryCodeList.ORMTB440CF01=='0'?'待接单':queryCodeList.ORMTB440CF01=='1'?'待提货':queryCodeList.ORMTB440CF01=='2'?'提货中':''||''}}</text>
				</view>
				<view><text>订单编号：</text>{{queryCodeList.ORMTB440CA00||''}}</view>
				<view><text>下单时间：</text>{{queryCodeList.ORMTB440CA19||''}}</view>
				<view><text>企业：</text>{{queryCodeList.ORMTB440CA24||''}}</view>
				<view><text>物料：</text>{{queryCodeList.ORMTB440CA07||''}}</view>
				<view>
					<text>下单方式：</text>{{queryCodeList.ORMTB440CA09=='JZ'?'净重':queryCodeList.ORMTB440CA09=='MZ'?'毛重':''||''}}
				</view>
				<view><text>吨数：</text>{{queryCodeList.ORMTB440CA10||''}}</view>
			</view> -->
		</view>
		<view class="zanWSJ" v-if="queryCodeList==''">
			<image :src="getStaticFilePath('/QXY/noData.png')" alt="">
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				screeningshow: false,
				codeShow: false,
				type: '', // 1 派单时间 2 结算时间
				//订单列表
				orderList: [],
				background: {
					background: '#42b983'
				},
				showCJ: false,
				fkID: '',
				title: '加油金账户',
				options2: [],
				brightness: null,
				current: 1, // tabs组件的current值，表示当前活动的tab选项
				swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的

				status: 'loading',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				countpage: 1,
				page: 1,
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				dataStatisCount: [],
				totalWeight: 0,
				totalAmount: 0,
				totalCarCount: 0,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				year: '',
				systemInfo: uni.getSystemInfoSync(),
				navHeight: '',
				optionHeight: 35,
				enterpriseName: '全部',
				erpshow: false,
				erpId: '',
				erpcColumns: [],
				stattimeshow: false,
				endtimeshow: false,
				dateStartStr: '',
				dateEndStr: '',
				materName: '全部',
				matershow: false,
				materColumns: [],
				materId: '',
				carshow: false,
				carNumberName: '全部车牌号',
				carkeyword: '',
				carKeyWordshow: false,
				carList: [],
				binary: '',
				ordercoutObj: '',
				AuthorizationOBJ: '',
				queryCodeList: '',
				testdata: {
					binary: '',
					queryCodeList: ''
				}
			};
		},
		onShow(e) {
			let that = this
			uni.$on('updateData', function(data) {
				that.testdata = data
				const params = 'binary:' + data.binary + ', queryCodeList:' + data.queryCodeList;
				console.log('监听到事件来自 updateData ，携带参数为：' + params);
				that.binary = data.binary
				that.queryCodeList = data.queryCodeList
			})
		},
		onLoad() {
			console.log(this.testdata)
			if (this.testdata.queryCodeList == '') {
				this.querycode()
			}
			this.jyjListFun()
			

			// 屏幕常亮
			// uni.setScreenBrightness({
			// 	value: 1,
			// 	success: function () {
			// 		console.log('success');
			// 	},
			// 	fail:function(){

			// 	}
			// });
		},

		mounted() {
			uni.getScreenBrightness({ // 获取屏幕亮度
				success: res => {
					if (res.value !== 1) {
						this.brightness = res.value // 屏幕亮度值，范围 0~1，0 最暗，1 最亮
						uni.setScreenBrightness({ // 设置屏幕亮度
							value: 1 // 屏幕亮度值，范围 0~1，0 最暗，1 最亮
						})
					}
				}
			})
		},
		beforeDestroy() {
			if (this.brightness != null) {
				uni.setScreenBrightness({ // 设置屏幕亮度到进入时的亮度
					value: this.brightness
				})
			}
		},

		methods: {
			querycode() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				this.binary = ''
				uni.request({
					url: this.baseUrl + '/orm/ormtb476/genQRcodeV2',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB410ID: this.userinfo.ORMTB410ID, //客户ID
						ORMTB410CA01: this.fkID,
					},
					success: (res) => {
						console.log(res);
						uni.hideLoading();
						if (res.data.code == 200) {
							var data = res.data.data
							if (data) {
								this.binary = 'data:image/png;base64,' + data
								this.queryCodeList = data
							}

						} else {
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
					},
					fail: (res) => {
						console.log(res)
						uni.hideLoading();
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
			jyjListFun() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				this.binary = ''
				uni.request({
					url: this.baseUrl + '/orm/ormtb481/ormtb481ListToPay',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB410CA04: this.userinfo.ORMTB410ID, //客户ID
					},
					success: (res) => {
						console.log(res);
						uni.hideLoading();
						if (res.data.code == 200) {
							var data = res.data.data
							// this.options2 = data.list
							
							data.list.forEach(item => {
								this.options2.push({
									label: item.DESC,
									value: item.ORMTB410CA01
								})
							})
							this.fkID = this.options2[0].value
							this.title = this.options2[0].label
							// if (data) {
							// 	this.binary = 'data:image/png;base64,' + data
							// 	this.queryCodeList = data
							// }

						} else {
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
					},
					fail: (res) => {
						console.log(res)
						uni.hideLoading();
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
			change(va) {

				let index = this.options2.findIndex(item => item.value == va); //根据 已知id（this.a_id） 获取在数组中的位置(index)；
				console.log(index)
				this.title = this.options2[index].label
				this.fkID = this.options2[index].value
				this.querycode()
			},
			open(index) {
				// 展开某个下来菜单时，先关闭原来的其他菜单的高亮
				// 同时内部会自动给当前展开项进行高亮
				// this.$refs.uDropdown.highlight();
			},
			close(va) {
				// 关闭的时候，给当前项加上高亮
				// 当然，您也可以通过监听dropdown-item的@change事件进行处理
				// this.$refs.uDropdown.highlight(index);

			},
			tabcl() {
				uni.navigateTo({
					url: '/pages/ordeVehicle/index'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.ewm-page {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
		background-color: #E3E3E3;
	}

	.ewm-main {
		background-color: #42b983;
		height: calc(100vh - var(--window-top));
	}

	.slot-wrap {
		display: flex;
		align-items: center;
		justify-content: space-between;
		/* 如果您想让slot内容占满整个导航栏的宽度 */
		flex: 1;
		/* 如果您想让slot内容与导航栏左右有空隙 */
		padding: 0 30rpx;
	}

	.ERcode-orderinfo {
		font-size: 36rpx;
		color: #333;
		margin-bottom: 65rpx;
		padding: 0 28rpx;
	}

	.ERcode-orderinfo>view {
		// height: 44rpx;
		line-height: 44rpx;
		overflow: hidden;
	}

	.ERcode-orderinfo-view {
		border-bottom: 2rpx solid #e3e3e3;
		padding-bottom: 20rpx;
	}

	.ERcode-orderinfo-view>text:first-child {
		font-size: 44rpx;
		font-weight: 600;
		width: 255rpx !important;
	}

	.ERcode-orderinfo>view+view {
		margin-top: 15rpx;
	}

	.ERcode-orderinfo text {
		display: inline-block;
		font-size: 36rpx;
		width: 190rpx;
		text-align: right;
		margin-right: 21rpx;
		color: #666;
	}

	.jym-fkm {
		text-align: center;
		background: #fff;
		border-radius: 20rpx;
		margin: 20rpx;
	}

	.code-img {
		// width: 100rpx;
		// height: 100rpx;
		// margin: 50rpx auto 0;
	}

	.code-img image {
		width: 400rpx;
		height: 400rpx;
	}

	.ykzhList {
		border-top: 2rpx solid rgba(153, 153, 153, 0.3);
		margin: 0 20rpx;
		padding-top: 20rpx;
		// display: flex;
		// justify-content: space-between;
	}

	.zanWSJ {
		padding-top: 200rpx;
	}

	.zanWSJ>image {
		display: block;
		margin: 0 auto;
		height: 360rpx;
		width: 43%;
	}


	::v-deep .u-dropdown__menu__item {
		display: inline-block;
	}

	::v-deep .u-flex {
		justify-content: space-between;
	}
</style>
